package sortmethod;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 冒泡排序，时间复杂度n²
 */
public class BubbleSort implements Sort {

    @Override
    public int[] sort(int[] input) {
        if (input == null || input.length < 1) {
            return null;
        }
        for (int i = 0; i < input.length - 1; i++) {
            for (int t = 0; t < input.length - 1 - i; t++) {
                if (input[t + 1] < input[t]) {
                    int temp = input[t + 1];
                    input[t + 1] = input[t];
                    input[t] = temp;
                }
            }
        }

        return input;

    }

    public static void main(String[] args) {
        int[] ints = new int[]{3456, 5, 3, 2, 324,4,213,18,232};
        int[] sort = new BubbleSort().sort(ints);
        String s = Arrays.toString(sort);
        System.out.println(s);

    }
}
